import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/h5/sys/exam_questions_public/list',
  lists = '/h5/sys/exam_questions_public/list',
  save='/h5/sys/exam_questions_public/add',
  edit='/h5/sys/exam_questions_public/edit',
  deleteOne = '/h5/sys/exam_questions_public/delete',
  deleteBatch = '/h5/sys/exam_questions_public/deleteBatch',
  importExcel = '/h5/sys/exam_questions_public/importExcel',
  exportXls = '/h5/sys/exam_questions_public/exportXls',
  queryDataById = '/h5/sys/exam_questions_public_public/queryById',
  examOptionsList = '/h5/sys/exam_questions_public/queryExamOptionsByMainId',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 查询子表数据
 * @param params
 */
export const queryExamOptionsListByMainId = (id) => defHttp.get({url: Api.examOptionsList, params:{ id }});

/**
 * 列表接口
 * @param params
 */
export const list = (params) =>{
  console.log(params,"params")
  params.isPublic = 3
  return defHttp.get({url: Api.list, params})
}
export const lists = async(param) =>{
  let params = {
    "column": "createTime",
    "order": "desc",
    "pageNo": 1,
    "pageSize": 1000,
    "bankId": param.bankid
}
console.log(params,"paramsparams")
  // options: [
  //   { title: '是', value: '1' },
  //   { title: '否', value: '0' },
  // ]
  let res = await defHttp.get({url: Api.list, params})
  console.log(res,"resresres")
  let data = []
  res.records.forEach(item=>{
    data.push({
      title:item.content,
      value:item.id
    })
  })
  console.log('zqt',res)
  return data
}
  


/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
* 根据id查询数据
* @param params
*/
export const queryDataById = (id) => defHttp.get({url: Api.queryDataById, params:{ id }});

